const btn_login = document.querySelector("#btn-login")
btn_login.addEventListener("click",function(){
    const login_form = document.querySelector(".login-form")
    const data = serialize(login_form,{hash:true,empty:true})
    
    axios({
        url:"/login",
        method:"post",
        data
    }).then(res => {
        console.log(res)
        // toastShow(res.message=="登录成功"?"登录成功":"请输入符合条件的用户名或密码")
        if(res.message == "登录成功"){
            toastShow("登录成功")
            setTimeout(() => {
                location.href = "./index.html"
            }, 1500);
        }else{
            toastShow("请输入符合条件的用户名或密码")
            return
        }

        //登录成功缓存数据
        localStorage.setItem("username",res.data.username)
        localStorage.setItem("token",res.data.token)
    }).catch(error => {
        console.log(error.response.data.message)
        toastShow(error.response.data.message)
    })
})